package com.jusda.nacosservice;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.jusda.nacosservice.config.NacosConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/nacos")
public class TestApi {

    @Autowired
    private NacosConfig nacosConfig;

    @NacosInjected
    private NamingService namingService;

    @GetMapping("/test1")
    public void test1(HttpServletRequest request) throws NacosException {
        List<Instance> allInstances = namingService.getAllInstances("nacos-service");
        for (Instance allInstance : allInstances) {
            System.out.println(allInstance.toString());
            System.out.println(allInstance.getInstanceId());
        }
        System.out.println(nacosConfig.getNacosCode());

        System.out.println(request.getServerPort());
    }


}